package com.peopledelete.controller;

import com.peopledelete.pojo.Day;
import com.peopledelete.service.OrigindayrecordsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.awt.*;
import java.math.BigDecimal;
import java.util.*;
import java.util.List;

/**
 * @author cyt
 * @create 2020-04-26 22:38
 */

@RestController
public class DayController {
    @Autowired
    OrigindayrecordsService service;


    @ResponseBody
    @RequestMapping("/getDayData")
    public ArrayList<Day> getDataDay(Integer hours) {

        System.out.println(hours);
        ArrayList<Day> list = new ArrayList<>();
        // 先查出来当天的记录数
        for (int i = 0; i < hours; i++) {
            List<Map<String, Object>> num = service.getDayOutInNum(i);
            for (Map<String, Object> map : num) {
                if (map != null) {
                    Day day = new Day();
                    int OutNum = ((BigDecimal) map.get("OutNum")).intValue();
                    int InNum = ((BigDecimal) map.get("InNum")).intValue();
                    System.out.println(InNum);
                    System.out.println(OutNum);
                    day.setInNum(InNum);
                    day.setOutNum(OutNum);
                    day.setHour(i);
                    list.add(day);
                }
            }
        }

        return list;
    }
}
